home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pckey.zip / PCKEY.CPP < prev    next >
C/C++ Source or Header  |  1991-03-24  |  2KB  |  106 lines

  1. /*
  2.  
  3.     pckey.cpp
  4.     3-24-91
  5.     PC keyboard class for Borland C++
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.     Use freely but acknowledge authorship and copyright.
  11.     CIS: 73757,2233
  12.  
  13.  
  14.     PSW / Power SoftWare
  15.     P.O. Box 10072
  16.     McLean, Virginia 22102 8072
  17.     (703) 759-3838
  18.  
  19. */
  20.  
  21. #include <pckey.hpp>
  22.  
  23. PCKey::PCKey()
  24. {
  25.     enhancedKeyBrd = 0;
  26.     flush();
  27.     (void) putch(0x3B00);
  28.     if (kbhit())  {
  29.     (void) getch();
  30.     enhancedKeyBrd = 0x10;
  31.     }
  32.     enhancedShiftMask = (enhancedKeyBrd)?
  33.     0xFFFF : 0x00FF;
  34.     asciiScan = 0;
  35. }
  36.  
  37. void PCKey::flush(void)
  38. {
  39.     while (kbhit())
  40.     (void) getch();
  41. }
  42.  
  43. // PCKey static member definitions
  44. unsigned PCKey::asciiScan;
  45. unsigned char PCKey::enhancedKeyBrd;
  46. unsigned PCKey::enhancedShiftMask;
  47.  
  48. PCKey PC;    // Only instance, do not instantiate!
  49.  
  50.  
  51. // Define TEST_PCKEY_CPP to test pckey.cpp as a stand
  52. // alone module.
  53. //#define TEST_PCKEY_CPP
  54.  
  55. #ifdef TEST_PCKEY_CPP
  56.  
  57. #include <stdio.h>
  58.  
  59. main()
  60. {
  61.     int ch;
  62.     unsigned lastShift = PC.shift();
  63.     puts("\n\nPress ESC to continue, any other key"
  64.         " to view ascii/scan code ...");
  65.     while (!PC.kbhit())
  66.         if (PC.shift() != lastShift)  {
  67.             lastShift = PC.shift();
  68.             printf("\n PC.shift(): %04x",
  69.                 PC.shift());
  70.         }
  71.     while ((ch = PC.getch()) != ESC)  {
  72.         printf("\n PC.getch(): %1c%1c     "
  73.             "PC.ascii():  %3d   "
  74.             "PC.scan(): %3d",
  75.             (ch <= 26 && ch)? '^':' ',
  76.             (ch <= 26 && ch)? ch+'@':ch,
  77.             PC.ascii(), PC.scan());
  78.         while (!PC.kbhit())
  79.             if (PC.shift() != lastShift)  {
  80.                 lastShift = PC.shift();
  81.                 printf("\n PC.shift(): "
  82.                     "%04x",PC.shift());
  83.             }
  84.     }
  85.     if (PC.enhanced())  {
  86.         puts("\n\nNow for the typematic test.  "
  87.             "Hold down any key to view the ");
  88.         puts("standard rates.  ESC for high "
  89.             "speed.\n");
  90.         ch = PC.getch();
  91.         while (ch != ESC)
  92.             putchar(ch = PC.getch());
  93.         puts("\n\nNow for highest speed hold "
  94.             "down any key.  ESC to quit.\n");
  95.         PC.setTypeMatic(TMR300,TMD250);
  96.         ch = PC.getch();
  97.         while (ch != ESC)
  98.             putchar(ch = PC.getch());
  99.         PC.setTypeMatic(TMR109,TMD500);
  100.     }
  101.     else
  102.         puts("\n\nKey board is not enhanced.");
  103.     return 0;
  104. }
  105.  
  106. #endif